package com.loukou.lkt.lkt.utils;

import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

import org.apache.log4j.Logger;

import com.loukou.core.httpclient.util.JsonUtil;

public abstract class GetUtils {
	static Logger logger = Logger.getLogger(GetUtils.class);
	
	public static Object getPhpData(String url){
	   try{
		   URL realUrl = new URL(url);
		   HttpURLConnection connection = (HttpURLConnection) realUrl.openConnection();
	       connection.setDoInput(true);
	       connection.setDoOutput(true);
	       connection.setRequestMethod("GET");
	       connection.setUseCaches(false);
	       connection.setInstanceFollowRedirects(true);
	       connection.setRequestProperty("Content-Type","application/json");
	       connection.connect();
	       DataOutputStream out = new DataOutputStream(connection.getOutputStream());
	       out.flush();
	       out.close();
	       BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
	       String lines;
	       StringBuffer sbf = new StringBuffer();
	       while ((lines = reader.readLine()) != null) {
               lines = new String(lines.getBytes(), "utf-8");
               sbf.append(lines);
	       }
	       Object result = JsonUtil.parseVO(sbf.toString(), Object.class);
	       reader.close();
           // 断开连接
           connection.disconnect(); 
           return result;
	   }catch(Exception ex){
		   logger.error("向"+url+"POST数据错误:" + ex.getMessage());
	   }
	   return null;
	}  

}
